﻿// Copyright (c) Sven Groot (Ookii.org) 2013
//
// This code is published under the Microsoft Public License (Ms-PL).  A copy
// of the license should be distributed with the code.  It can also be found
// at http://ookiicommandline.codeplex.com. This notice, the author's name,
// and all copyright notices must remain intact in all applications,
// documentation, and source files.using System;
using System;
using System.Collections.Generic;
using System.Text;

namespace Ookii.CommandLine
{
    /// <summary>
    /// Defines an alternative name for a command line argument.
    /// </summary>
    /// <remarks>
    /// <note>
    ///   To specify multiple aliases, apply this attribute multiple times.
    /// </note>
    /// <para>
    ///   The aliases for a command line argument can be used instead of their regular name to specify the parameter on the command line.
    ///   For example, this can be used to have a shorter name for an argument (e.g. "-v" as an alternative to "-Verbose").
    /// </para>
    /// <para>
    ///   All regular command line argument names and aliases used by an instance of the <see cref="CommandLineParser"/> class must be
    ///   unique.
    /// </para>
    /// <para>
    ///   By default, the command line usage help generated by <see cref="CommandLineParser.WriteUsage(System.IO.TextWriter,int,WriteUsageOptions)"/>
    ///   does not list the aliases. Either manually add them to the description, or set the <see cref="WriteUsageOptions.IncludeAliasInDescription"/>
    ///   property to <see langword="true"/>.
    /// </para>
    /// </remarks>
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple=true)]
    public sealed class AliasAttribute : Attribute
    {
        private readonly string _alias;

        /// <summary>
        /// Initializes a new instance of the <see cref="AliasAttribute"/> class.
        /// </summary>
        /// <param name="alias">The alternative name for the command line argument.</param>
        public AliasAttribute(string alias)
        {
            if( alias == null )
                throw new ArgumentNullException("alias");
            _alias = alias;
        }

        /// <summary>
        /// Gets the alternative name for the command line argument.
        /// </summary>
        /// <value>
        /// The alternative name for the command line argument.
        /// </value>
        public string Alias
        {
            get { return _alias; }
        }
    }
}
